﻿/**
 * MsgViewer
 *
 * MsgViewer class displays the provided message.
 *
 * MsgViewer is part of the sample application for the presentation on Flash ActionScript Cafe's 2nd conference.
 * 
 *
 * @author: Han Sanghun (http://hangunsworld.com, hanguns@gmail.com)
 * @created: 2008 05 19
 * @last modified: 2008 05 24
 */

package conf{
	
	import flash.display.*;
	import flash.events.*;
	import flash.filters.ColorMatrixFilter;
	import flash.text.*;
	
	
	public class MsgViewer extends Sprite{
		
		private var _root:MovieClip;
		
		private var bd:BitmapData;
		private var bmp:Bitmap;
		
		public var mc:MovieClip;
		/**
		 * Constructor function.
		 *
		 * @param str 팝업에 표시할 문자열
		 * @param closable 마우스 클릭으로 팝업을 닫기 가능 여부
		 */
		public function MsgViewer(str:String, closable:Boolean=false){
//			mc = mv as MovieClip;
//			mc.msg_txt.multiline = true;
//			mc.msg_txt.autoSize = TextFieldAutoSize.CENTER;
//			
//			mc.msg_txt.text = str;
//			
//			if(closable){
//				addEventListener(MouseEvent.CLICK, clickListener);
//			}
//			
//			addEventListener(Event.ADDED_TO_STAGE, addedListener);
			
		}// end constructor function
		
		
		/**
		 * 스테이지에 애드되면, 초기화 실행하기
		 */
		private function addedListener(e:Event):void{
			
			_root = root as MovieClip;
			
			visible = false;
			
			// 전체화면 비트맵화
			bd = new BitmapData(stage.stageWidth, stage.stageHeight);
			bd.draw(root);
			
			// 비트맵에 그레이스케일 적용
			bmp = new Bitmap(bd);
			bmp.filters = [new ColorMatrixFilter([.3086, .6094, .0820, 0, 0, .3086, .6094, .0820, 0, 0, .3086, .6094, .0820, 0, 0, 0, 0, 0, 1])];
			addChildAt(bmp, 0);
			
			mc.msg_txt.x = (stage.stageWidth - mc.msg_txt.width) / 2;
			mc.msg_txt.y = (stage.stageHeight - mc.msg_txt.height) / 2;
			
			
			visible = true;
			
		}// end addedListener
		
		
		/**
		 * 클릭하면, MsgViewer 제거
		 */
		private function clickListener(e:MouseEvent):void{
			
			_root.hideMessage();
			
		}// end clickListener
		
		
		/**
		 * 메세지 변경하기
		 *
		 * @param str 팝업에 표시할 문자열
		 * @param closable 마우스 클릭으로 팝업을 닫기 가능 여부
		 */
		public function setMessage(str:String, closable:Boolean=false):void{
			return;
			mc.msg_txt.text = str;
			
			mc.msg_txt.x = (stage.stageWidth - mc.msg_txt.width) / 2;
			mc.msg_txt.y = (stage.stageHeight - mc.msg_txt.height) / 2;
			
			// 닫기 가능인 경우만 마우스이벤트 적용
			removeEventListener(Event.ADDED_TO_STAGE, addedListener);
			if(closable){
				addEventListener(Event.ADDED_TO_STAGE, addedListener);
			}
			
		}// end setMessage
		
	}// end class
}// end package